package com.ysw.util;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * @ClassName PropertiesUtil
 * @Description TODO
 * @Author ysw
 * @Date 2021/12/12 20:32
 */
public class PropertiesUtil {
    public static Properties loadProperties(String path) throws IOException {
        ClassPathResource classPathResource = new ClassPathResource(path);
        Properties properties = PropertiesLoaderUtils.loadProperties(classPathResource);
        return properties;
    }

    public static Properties loadProperties2(String path) throws IOException {
        InputStream resourceAsStream = PropertiesUtil.class.getClassLoader().getResourceAsStream(path);
        InputStreamReader inputStreamReader = new InputStreamReader(resourceAsStream, "utf-8");
        Properties pro = new Properties();
        pro.load(inputStreamReader);
        return pro;
    }

    public static void main(String[] args) throws IOException {
        Properties properties = loadProperties2("producer.properties");
        System.out.println(properties);
    }
}